package org.dce.screencapturer.actions.ui;

import java.awt.event.ActionEvent;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JFileChooser;

import org.dce.screencapturer.Drawing;
import org.dce.screencapturer.UI;
import org.dce.screencapturer.actions.ScreenCapturerAction;
import org.dce.screencapturer.util.IconFactory;

@SuppressWarnings("serial")
public class NewImageAction extends ScreenCapturerAction {
	
	public NewImageAction() {
		super("categories.file", "actions.newFromFile",IconFactory.getIcon("/images/document-open.png"));
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		JFileChooser chooser = new JFileChooser();
		
		UI ui = getUI();
		
		if (chooser.showOpenDialog(ui) == JFileChooser.APPROVE_OPTION){
			File file = chooser.getSelectedFile();
			
			try {
				ui.addDrawing(new Drawing(ImageIO.read(file)));
			}catch (Exception ex){
				ex.printStackTrace();
			}
			
		}

	}

}
